import Vue from 'vue'
import { ACCESS_TOKEN } from '@/store/mutation-types'
import { welcome } from '@/utils/util'
const user = {
  state: {
    userId: '',
    token: '',
    name: '',
    welcome: '',
    avatar: '',
    roles: [],
    buttons: [], // 按钮权限
    info: {}
  },

  mutations: {
    SET_TOKEN: (state, token) => {
      state.token = token
    },
    SET_NAME: (state, { name, welcome }) => {
      state.name = name
      state.welcome = welcome
    },
    SET_AVATAR: (state, avatar) => {
      state.avatar = avatar
    },
    SET_ROLES: (state, roles) => {
      state.roles = roles
    },
    SET_INFO: (state, info) => {
      state.info = info
    },
    SET_BUTTONS: (state, buttons) => {
      state.buttons = buttons
    },
    SET_USERID: (state, userId) => {
      state.userId = userId
    }
  },

  actions: {
    // 第三方页面跳转设置- 2021-07-31 start
    SetInfo ({ commit }, userInfo) {
      console.log(userInfo)
      Vue.ls.set(ACCESS_TOKEN, userInfo.token)
      Vue.ls.set('username', userInfo.username)
      Vue.ls.set('withoutLoginPush', userInfo.subMenu)
      if (userInfo.hiddenHeader) {
        Vue.ls.set('hiddenHeader', userInfo.hiddenHeader)
      }
      commit('SET_TOKEN', userInfo.token)
    },
    // 第三方页面跳转设置- 2021-07-31 end

    // 第三方页面跳转设置- 2021-11-26 start
    SetAqyptInfo ({ commit }, userInfo) {
      console.log(userInfo)
      Vue.ls.set(ACCESS_TOKEN, userInfo.token)
      Vue.ls.set('username', userInfo.username)
      commit('SET_TOKEN', userInfo.token)
    },

    // 登出
    getLoginRemote (commit, params) {
      return new Promise((resolve) => {
        getLoginRemote(params).then((response) => {
          resolve(response)
        }).catch((response) => {
          resolve(response)
        })
      })
    },

    getAnnouncement (commit, params) {
      return new Promise((resolve) => {
        getAnnouncement(params).then((response) => {
          resolve(response)
        }).catch((response) => {
          resolve(response)
        })
      })
    },

    updateLoginRemote (commit, params) {
      return new Promise((resolve) => {
        updateLoginRemote(params).then((response) => {
          resolve(response)
        }).catch((response) => {
          resolve(response)
        })
      })
    },

    getLoginDeviceRegister (commit, params) {
      return new Promise((resolve) => {
        getLoginDeviceRegister(params).then((response) => {
          resolve(response)
        }).catch((response) => {
          resolve(response)
        })
      })
    },

    updateLoginDeviceRegister (commit, params) {
      return new Promise((resolve) => {
        updateLoginDeviceRegister(params).then((response) => {
          resolve(response)
        }).catch((response) => {
          resolve(response)
        })
      })
    },

    getLogininfor (commit, params) {
      return new Promise((resolve) => {
        getLogininfor(params).then((response) => {
          resolve(response)
        }).catch((response) => {
          resolve(response)
        })
      })
    },

    remoteUpdateStatus () {
      return new Promise((resolve) => {
        remoteUpdateStatus().then((response) => {
          resolve(response)
        }).catch((response) => {
          resolve(response)
        })
      })
    },

    deviceRegisterUpdateStatus () {
      return new Promise((resolve) => {
        deviceRegisterUpdateStatus().then((response) => {
          resolve(response)
        }).catch((response) => {
          resolve(response)
        })
      })
    },
    getDeviceDisconnect (commit, params) {
      return new Promise((resolve) => {
        getDeviceDisconnect(params).then((response) => {
          resolve(response)
        }).catch((response) => {
          resolve(response)
        })
      })
    },
    deviceDisconnectMsgUpdate (commit, params) {
      return new Promise((resolve) => {
        deviceDisconnectMsgUpdate(params).then((response) => {
          resolve(response)
        }).catch((response) => {
          resolve(response)
        })
      })
    },
    deviceDisconnectMsgAllRead (commit, params) {
      return new Promise((resolve) => {
        deviceDisconnectMsgAllRead(params).then((response) => {
          resolve(response)
        }).catch((response) => {
          resolve(response)
        })
      })
    },
    getDict (commit, params) {
      return new Promise((resolve) => {
        getDictDataList(params).then((response) => {
          resolve(response)
        }).catch((response) => {
          resolve(response)
        })
      })
    },
    getUsersByPhone (commit, params) {
      return new Promise((resolve) => {
        getUsersByPhone(params).then((response) => {
          resolve(response)
        }).catch((response) => {
          resolve(response)
        })
      })
    },

    loginByUserId (commit, params) {
      return new Promise((resolve) => {
        loginByUserId(params).then((response) => {
          resolve(response)
        }).catch((response) => {
          resolve(response)
        })
      })
    }
  }
}

export default user
